package com.wtwd.campus.receiver;

import com.wtwd.campus.entity.MqCallNoteMessage;
import com.wtwd.campus.entity.MqLocationData;
import com.wtwd.campus.service.IRMFeignClientService;
import com.wtwd.campus.service.InjectFeignService;
import com.wtwd.campus.utils.LocationUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class UploadCallRecordsReceiver implements Receiver {
    @Autowired
    private IRMFeignClientService irmFeignClientService;
    @Override
    public String parseMessage(String data) {
        //*WT,866248050395985,CALLNOTE,092808,18797874506,1,0,V,0.0000,S,0.0000,W,0.00,0,040621,FFDFFFFF#
        //分割字符串获取指令信息
        String[] split = data.split(",");
        String imei=split[1];
        String messageType = split[2];
        String commandNumber=split[3];
        String callNum=split[4];//来去电号码
        String callType=split[5];//来去电类型 0-来电 1-去电
        String callTime=split[6];//通话时长
        String lat = split[8];
        String lng = split[10];
        String speed = split[12];
        String orientation = split[13];
        String date = split[14];//日月年
        String deviceStatus = split[15];//设备状态
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        MqCallNoteMessage mqCallNoteMessage = new MqCallNoteMessage();
        mqCallNoteMessage.setCallType(Integer.parseInt(callType));
        mqCallNoteMessage.setCommandNumber(commandNumber);
        mqCallNoteMessage.setDeviceDate(date);
        mqCallNoteMessage.setImei(imei);
        mqCallNoteMessage.setDeviceTime(commandNumber);
        mqCallNoteMessage.setPhone(callNum);
        mqCallNoteMessage.setDuration(callTime);
        MqLocationData mqLocationData = new MqLocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        mqCallNoteMessage.setMqLocationData(mqLocationData);
        InjectFeignService.getIrmFeignClientService().upCallNoteMessage(mqCallNoteMessage);
        return imei;
    }
}
